package com.tanhua.test;

import com.baidu.aip.face.AipFace;
import com.tanhua.autoconfig.TanhuaAutoConfiguration;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/11/27 18:30
 */

@SpringBootTest(classes = TanhuaAutoConfiguration.class)
@RunWith(SpringRunner.class)
public class ApiFace {

    //设置APPID/AK/SK
    public static final String APP_ID = "24021388";
    public static final String API_KEY = "5dfbcba4406844e599ce4fde0bbbf9d1";
    public static final String SECRET_KEY = "317c66714d84486b875c47dbe4e8dcaa";

    @Test
    public void face() {

        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");

        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);
        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 调用接口
        String image = "https://007tanhua.oss-cn-beijing.aliyuncs.com/2021/11/27/0d4b5e22-abb9-42da-9874-7dc9d85f0163.jpg";
        String imageType = "URL";
        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));
        Integer error_code = (Integer) res.get("error_code");
        System.out.println(error_code);
    }

}
